package com.coolpad.job.device.dao.provider;

import com.coolpad.job.device.model.CityPartitionPO;
import com.coolpad.job.device.model.Point;
import com.coolpad.job.device.util.NumberUtils;
import com.coolpad.job.device.util.RailScanUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Slf4j
public class GeoInfoProvider {

    public String batchInsertPoint(Map<String,Object> map){
        List<Point> pointList = (List<Point>)map.get("list");
        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO t_geo_full_info (partition_id,lon,lat,county_id) VALUES");
        for (int i = 0; i < pointList.size(); i++) {
            String lon = NumberUtils.format(pointList.get(i).getX(), RailScanUtils.scan_length);
            String lat = NumberUtils.format(pointList.get(i).getY(), RailScanUtils.scan_length);
            String countyId = pointList.get(i).getCountyId();
            sb.append(String.format("(%s,'%s','%s',%s)", 0, lon, lat, countyId));
            if (i < pointList.size() - 1) {
                sb.append(",");
            }
        }
        return sb.toString();
    }

    public String batchInsertCity(Map<String,Object> map){
        List<CityPartitionPO> list = (List<CityPartitionPO>)map.get("list");
        StringBuilder sb = new StringBuilder();
        sb.append("INSERT INTO t_china_city_partition (partition_id,province_id,province_name,city_id,city_name,county_id,county_name,town_id,town_name) VALUES");
        for (int i = 0; i < list.size(); i++) {
            CityPartitionPO city = list.get(i);
            long partitionId = city.getPartitionId();
            long provinceId = city.getProvinceId();
            String provinceName = city.getProvinceName();
            long cityId = city.getCityId();
            String cityName = city.getCityName();
            long countyId = city.getCountyId();
            String countyName = city.getCountyName();
            long townId = city.getTownId();
            String townName = city.getTownName();
            sb.append(String.format("(%s, %s,'%s', %s,'%s', %s,'%s',%s,'%s')",partitionId,provinceId,provinceName,cityId,cityName,countyId,countyName,townId,townName));
            if (i < list.size() - 1) {
                sb.append(",");
            }
        }
        return sb.toString();
    }

}
